package com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.riskamount;

import com.bmps.springcloud.common.utils.DateUtil;
import com.bmps.springcloud.insuredmicroservice.model.accept.medium.PolicyRiskInfoModel;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * description:
 * HDT013风险保额计算
 * 风险保额：未交费年限*保额
 *
 * @author jackdaw
 * @date 2020-04-16 14:59
 */
@Component
public class Hdt013Strategy implements InsuranceRiskAmountStrategy {
    @Override
    public BigDecimal getRiskAmount(PolicyRiskInfoModel policyRiskInfoModel, boolean isCurrent, Object object) {
        if (isCurrent || policyRiskInfoModel.getPayTodate() == null) {
            return policyRiskInfoModel.getAmnt().multiply(BigDecimal.valueOf(policyRiskInfoModel.getPayYears()));
        }
        return policyRiskInfoModel.getAmnt().multiply(BigDecimal.valueOf(DateUtil.getYears(policyRiskInfoModel.getPayTodate(), policyRiskInfoModel.getPayEndDate())));
    }
}
